package com.zhongying.jf.util.sms253;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class CodeUtil {

    // 日志记录
    private static final Logger logger = LoggerFactory.getLogger(CodeUtil.class);

    public static String decode(String param) {
        try {
            if (param == null || param.trim().length() == 0) {
                return param;
            }
            param = URLDecoder.decode(param, "utf-8");
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
            logger.info("参数解析失败:" + ex.getMessage());
        }
        return param;
    }

    public static String encode(String param) {
        try {
            if (param == null || param.trim().length() == 0) {
                return param;
            }
            param = URLEncoder.encode(param, "utf-8");
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
            logger.info("参数解析失败:" + ex.getMessage());
        }
        return param;
    }

}
